import 'package:flutter/material.dart';
import 'package:flutter_project_mk/flutter_layout_page.dart';
import 'package:flutter_project_mk/gesture_page.dart';
import 'package:flutter_project_mk/logo_app.dart';
import 'package:flutter_project_mk/logo_app_build.dart';
import 'package:flutter_project_mk/logo_app_widget.dart';
import 'package:flutter_project_mk/open_third_party.dart';
import 'package:flutter_project_mk/photo_app_page.dart';
import 'package:flutter_project_mk/radiaHero.dart';
import 'package:flutter_project_mk/res_page.dart';
import 'package:flutter_project_mk/stateful_group_page.dart';
import 'package:flutter_project_mk/hero.dart';
import 'less_group_page.dart';

void main()=>runApp(MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter project mk',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.lightBlue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('显示的内容'),
        ),
        body: RouterNavigatorState(),
      ),
      routes: <String,WidgetBuilder>{
        'less':(BuildContext context)=>LessGroupPage(),
        'ful':(BuildContext context)=>StateFulGroupPage(),
        'layout':(BuildContext context)=>FlutterLayoutPage(),
        'gsture':(BuildContext contex)=>GesturePage(),
        'openThird':(BuildContext context)=>OpenThirdParty(),
        'photo':(BuildContext context)=>PhotoAppPage(),
        'logoapp':(BuildContext context)=>LogoApp(),
        'logowidget':(BuildContext context)=>LogoAppWidget(),
        'logobuild':(BuildContext context)=>LogoAppBuild(),
        'hero':(BuildContext context)=>HeroAnimation(),
        'Rahero':(BuildContext context)=>RadialExpansionDemo(),
      },
    );
  }
}

class RouterNavigatorState extends StatefulWidget {
  @override
  _RouterNavigatorStateState createState() => _RouterNavigatorStateState();
}

class _RouterNavigatorStateState extends State<RouterNavigatorState> {
  bool byName = false;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            SwitchListTile(
                title: Text('${byName?'':'不'}通过路由名跳转'),
                value: byName,onChanged: (value){
              setState(() {
                byName = value;
              });
            }),
            _item('StateLess基本组件',LessGroupPage(),'less'),
            _item('ful基本组件',StateFulGroupPage(),'ful'),
            _item('layout基本组件',FlutterLayoutPage(),'layout'),
            _item('检测手势响应',GesturePage(),'gsture'),
            _item('静态资源导入',ResPage(),'respage'),
            _item('打开第三方链接',OpenThirdParty(),'openThird'),
            _item('拍照App', PhotoAppPage(), 'photo'),
            _item('动画',LogoApp(),'logoapp'),
            _item('动画AnimationWidget',LogoAppWidget(),'logowidget'),
            _item('动画AnimationBuild',LogoAppBuild(),'logobuild'),
            _item('hero动画(图片)', HeroAnimation(), 'hero'),
            _item('hero径向动画', RadialExpansionDemo(), 'Rahero'),
          ],
        ),
      ),
    );
  }

  _item(String title,page, String routeName) {
    return Container(
      child: RaisedButton(
          onPressed: (){
            if(byName){
              Navigator.pushNamed(context, routeName);
            }else{
              Navigator.push(context, MaterialPageRoute(builder: (context)=>page));
            }
          },
          child: Text(title),
          ),
    );
  }
}

